package com.example.b_308.software.view.base;

import android.content.Intent;
import android.os.Bundle;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;


import com.example.b_308.software.R;
import com.example.b_308.software.comment.view.title.TitleBar;
import com.example.b_308.software.comment.view.title.util.AppUtils;
import com.example.b_308.software.comment.view.title.util.Globel;

/**
 * Created by B-308 on 2017/11/15.
 */

import java.io.Serializable;

public abstract class BaseActivity extends AppCompatActivity implements IBaseView {
    AlertDialog alertDialog;
    AlertDialog.Builder builder;
    LinearLayout ll;
    TitleBar titleBar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.activity_base);
        if (null != getSupportActionBar())
            getSupportActionBar().hide();
       Globel.init(this);
      Globel.setNoStatusBarFullMode(this);
        ll = (LinearLayout) findViewById(R.id.ll);
        titleBar = (TitleBar) findViewById(R.id.title_bar);
       titleBar.setPadding(0,(int) AppUtils.getStatusBarHeight(this), 0, 0);
        builder=new  AlertDialog.Builder(this);
    }

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        ll.addView(LayoutInflater.from(this).inflate(layoutResID, null));
    }

    public TitleBar getTitleBar() {
        return titleBar;
    }


    public void fail(String  message) {
        builder.setTitle("提示").setMessage(message).setPositiveButton("确定",null);
     alertDialog=builder.create();
        alertDialog.show();
    }

    public void tent2(Class cla){
        startActivity(new Intent(this,cla));
    }

    public <T> void tentForResult(Class cla,int requestCode){
        Intent intent=new Intent(this,cla);
        startActivityForResult(intent,requestCode);
    }

    public <T> void tend2(Class cla,T t,String key){
        Intent intent = new Intent(this,cla);


        if (t instanceof String){
            intent.putExtra(key,(String)t);
        }
        if (t instanceof String[]){
            intent.putExtra(key,(String[])t);
        }
        if (t instanceof Long){
            intent.putExtra(key,(Long)t);
        }
        if (t instanceof Integer){
            intent.putExtra(key,(Integer) t);
        }
        if (t instanceof Double){
            intent.putExtra(key,(Double) t);
        }
        if (t instanceof Serializable){
            intent.putExtra(key,(Serializable)t);
        }
    }
    public <T extends View>T findView(int recourceId){
        return (T) findViewById(recourceId);
    }

}